package cn.itcast.com.Object.clone;

public class demo2 {
    public static void main(String[] args) throws CloneNotSupportedException {
        int i = 100;
        double j = 9.8;
        SecondLevel secondLevel;
        ThirdLevel thirdLevel = new ThirdLevel(300,33.3);


    }

}

class FirstLevel{
    int firstIntValue;
    double firstDoubleValue;
    SecondLevel secondLevel;
    public FirstLevel(int firstIntValue, double firstDoubleValue) {
        this.firstIntValue = firstIntValue;
        this.firstDoubleValue = firstDoubleValue;
    }

    public FirstLevel(int firstIntValue, double firstDoubleValue, SecondLevel secondLevel) {
        this.firstIntValue = firstIntValue;
        this.firstDoubleValue = firstDoubleValue;
        this.secondLevel = secondLevel;
    }

    @Override
    protected FirstLevel clone() throws CloneNotSupportedException {
        //先实现浅拷贝
        FirstLevel cloneobj = (FirstLevel) super.clone();
        //针对当前类中定义的引用类型的成员变量实现深拷贝
        //cloneobj.second =
        return cloneobj;
    }

    @Override
    public String toString() {
        return "FirstLevel{" +
                "firstIntValue=" + firstIntValue +
                ", firstDoubleValue=" + firstDoubleValue +
                '}';
    }
}
class SecondLevel implements Cloneable{
    int secondIntValue;
    double secondDoubleValue;
    ThirdLevel third;

    @Override
    protected SecondLevel clone() throws CloneNotSupportedException {
        //首先堆当前的second对象进行浅拷贝
        SecondLevel cloneobj = (SecondLevel) super.clone();
        //修改浅拷贝，复制对象的，引用变量值
        //cloneobj.thrid =
        return cloneobj;
    }

    public SecondLevel(int secondIntValue, double secondDoubleValue, ThirdLevel third) {
        this.secondIntValue = secondIntValue;
        this.secondDoubleValue = secondDoubleValue;
        this.third = third;
    }

    @Override
    public String toString() {
        return "SecondLevel{" +
                "secondIntValue=" + secondIntValue +
                ", secondDoubleValue=" + secondDoubleValue +
                ", third=" + third +
                '}';
    }
}

class ThirdLevel{
    int thirdIntValue;
    double thirdDoubleValue;
    ThirdLevel third;

    @Override
    protected ThirdLevel clone() throws CloneNotSupportedException {
        return (ThirdLevel) super.clone();
    }

    public ThirdLevel(int thirdIntValue, double thirdDoubleValue) {
        this.thirdIntValue = thirdIntValue;
        this.thirdDoubleValue = thirdDoubleValue;
    }

    public ThirdLevel(int thirdIntValue, double thirdDoubleValue, ThirdLevel third) {
        this.thirdIntValue = thirdIntValue;
        this.thirdDoubleValue = thirdDoubleValue;
        this.third = third;
    }

    @Override
    public String toString() {
        return "ThirdLevel{" +
                "thirdIntValue=" + thirdIntValue +
                ", thirdDoubleValue=" + thirdDoubleValue +
                '}';
    }
}